<style>
    #upload {
        opacity: 0;
    }
    
    #img {
        display: block;
        border: 1px solid #999;
        height: 198px;
        width: 198px;
        /* line-height:118px; */
        cursor: pointer;
        margin-top: -20px;
    }
</style>
<!--页面主要内容-->
<main class="lyear-layout-content">

    <div class="container-fluid">

        <div class="row">
            <div class="col-lg-12">
                <div class="card">
                    <div class="card-body">

                        <form method="post" class="row" enctype="multipart/form-data">


                            <div class="form-group col-md-12">
                                <label for="title">配置标题</label>
                                <input type="text" class="form-control" id="title" name="title" value="" placeholder="请输入标题" />
                            </div>

                            <div class="form-group col-md-12">
                                <label for="key">配置名称</label>
                                <input type="text" class="form-control" id="key" name="key" value="" placeholder="请输入配置名称" />
                            </div>
                            <div class="form-group col-md-12">
                                <label for="type">配置类型</label>
                                <div class="form-controls">
                                    <select name="type" class="form-control" id="type">
                      <option value="text">文本类型</option>
                      <option value="file">文件类型</option>
                    </select>
                                </div>
                            </div>

                            <div class="form-group col-md-12" id="text">
                                <label for="value">配置的值</label>
                                <input type="text" class="form-control" id="value" name="value" value="" placeholder="请输入配置值" />
                            </div>

                            <div class="form-group col-md-12" id="file" hidden>
                                <label>配置的值</label>
                                <!-- <div class="form-controls"> -->
                                <input type="file" name="file" class="input-xxlarge" id="upload">
                                <label for="upload" style="margin-bottom:0;width: 198px;">
                      <img src="/static/admin/images/upload.png" alt="" id="img" />
                    </label>
                                <!-- <ul class="list-inline clearfix lyear-uploads-pic">
                      
                      <li class="col-xs-4 col-sm-3 col-md-2">
                        <a class="pic-add" id="add-pic-btn" href="#!" title="点击上传"></a>
                      </li>
                    </ul> -->
                                <!-- </div> -->
                            </div>



                            <div class="form-group col-md-12">
                                <button type="submit" class="btn btn-primary " target-form="add-form">确 定</button>
                                <button type="button" class="btn btn-default" onclick="javascript:history.back(-1);return false;">返
                    回</button>
                            </div>
                        </form>

                    </div>
                </div>
            </div>

        </div>

    </div>

</main>
<!--End 页面主要内容-->
<script>
    function getObjectURL(file) {
        var url = null;
        if (window.createObjectURL != undefined) { // basic
            url = window.createObjectURL(file);
        } else if (window.URL != undefined) { // mozilla(firefox)
            url = window.URL.createObjectURL(file);
        } else if (window.webkitURL != undefined) { // webkit or chrome
            url = window.webkitURL.createObjectURL(file);
        }
        return url;
    }

    $('#upload').change(function() {
        var url = getObjectURL(this.files[0]);
        if (url) {
            $('#img').attr('src', url);
        }
    });

    $('#type').change(function() {
        var type = $(this).val();
        if (type == 'text') {
            $('#text').removeAttr('hidden');
            $('#file').attr('hidden', true);
        } else if (type == 'file') {
            $('#file').removeAttr('hidden');
            $('#text').attr('hidden', true);
        }
    })
    
</script>